package com.platform.core.entity.listener;

import com.platform.core.entity.SysUser;
import lombok.extern.slf4j.Slf4j;

import javax.persistence.PostLoad;
import javax.persistence.PostPersist;
import javax.persistence.PostRemove;
import javax.persistence.PostUpdate;
import javax.persistence.PrePersist;
import javax.persistence.PreRemove;
import javax.persistence.PreUpdate;

/**
 * Description: JPA监听器
 *
 * @author libin Created on 2019/7/25
 **/
@Slf4j
public class SysUserEntityListener {
    @PrePersist
    public void userPrePersist(SysUser ob) {
        print("Listening User Pre Persist : " + ob.getUsername());
    }

    @PostPersist
    public void userPostPersist(SysUser ob) {
        print("Listening User Post Persist : " + ob.getUsername());
    }

    @PostLoad
    public void userPostLoad(SysUser ob) {
        print("Listening User Post Load : " + ob.getUsername());
    }

    @PreUpdate
    public void userPreUpdate(SysUser ob) {
        print("Listening User Pre Update : " + ob.getUsername());
    }

    @PostUpdate
    public void userPostUpdate(SysUser ob) {
        print("Listening User Post Update : " + ob.getUsername());
    }

    @PreRemove
    public void userPreRemove(SysUser ob) {
        print("Listening User Pre Remove : " + ob.getUsername());
    }

    @PostRemove
    public void userPostRemove(SysUser ob) {
        print("Listening User Post Remove : " + ob.getUsername());
    }

    private void print(String msg) {
        if (log.isDebugEnabled()) {
            log.debug(msg);
        }
    }
}
